import { TypeOrmModuleOptions } from "@nestjs/typeorm";

// eslint-disable-next-line @typescript-eslint/no-var-requires
require("dotenv").config();
//1.加载环境文件
// eslint-disable-next-line @typescript-eslint/no-var-requires
const envPath = require("path").join(
  process.cwd(),
  `/config/${process.env.NODE_ENV || "dev"}.yaml`
);
// eslint-disable-next-line @typescript-eslint/no-var-requires
const config = require("dotenv-yaml").config({ path: envPath }).parsed;
class ConfigService {
  public isProduction() {
    return false;
  }

  public getTypeOrmConfig(): TypeOrmModuleOptions {
    return {
      type: "postgres",
      entities: ["dist/**/*.entity{.ts,.js}"],
      migrationsTableName: "migration",
      migrations: ["src/migration/*.ts"],
      logger: "debug",
      cli: {
        migrationsDir: "src/migration",
      },
      ssl: this.isProduction(),
      ...(config && config.postgres),
    };
  }
}

const configService = new ConfigService();

export { configService };
